package com.cykj.pos.controller.api;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cykj.common.annotation.Log;
import com.cykj.common.core.controller.BaseController;
import com.cykj.common.core.domain.AjaxResult;
import com.cykj.common.enums.BusinessType;
import com.cykj.pos.domain.AizDeductionRecords;
import com.cykj.pos.service.IAizDeductionRecordsService;
import com.cykj.common.utils.poi.ExcelUtil;
import com.cykj.common.core.page.TableDataInfo;

/**
 * 未/未激活扣款记录Controller
 *
 * @author weijianbo
 * @date 2025-03-05
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/pos/deduction/records" )
public class AizDeductionRecordsController extends BaseController {

    private final IAizDeductionRecordsService iAizDeductionRecordsService;

    /**
     * 查询未/未激活扣款记录列表
     */
    @PreAuthorize("@ss.hasPermi('pos:records:list')")
    @GetMapping("/list")
    public TableDataInfo list(AizDeductionRecords aizDeductionRecords) {
        startPage();
        List<AizDeductionRecords> list = iAizDeductionRecordsService.queryList(aizDeductionRecords);
        return getDataTable(list);
    }

    /**
     * 导出未/未激活扣款记录列表
     */
    @PreAuthorize("@ss.hasPermi('pos:records:export')" )
    @Log(title = "未/未激活扣款记录" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(AizDeductionRecords aizDeductionRecords) {
        List<AizDeductionRecords> list = iAizDeductionRecordsService.queryList(aizDeductionRecords);
        ExcelUtil<AizDeductionRecords> util = new ExcelUtil<AizDeductionRecords>(AizDeductionRecords.class);
        return util.exportExcel(list, "records" );
    }

    /**
     * 获取未/未激活扣款记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('pos:records:query')" )
    @GetMapping(value = "/{deductionId}" )
    public AjaxResult getInfo(@PathVariable("deductionId" ) Long deductionId) {
        return AjaxResult.success(iAizDeductionRecordsService.getById(deductionId));
    }

    /**
     * 新增未/未激活扣款记录
     */
    @PreAuthorize("@ss.hasPermi('pos:records:add')" )
    @Log(title = "未/未激活扣款记录" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AizDeductionRecords aizDeductionRecords) {
        return toAjax(iAizDeductionRecordsService.save(aizDeductionRecords) ? 1 : 0);
    }

    /**
     * 修改未/未激活扣款记录
     */
    @PreAuthorize("@ss.hasPermi('pos:records:edit')" )
    @Log(title = "未/未激活扣款记录" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AizDeductionRecords aizDeductionRecords) {
        return toAjax(iAizDeductionRecordsService.updateById(aizDeductionRecords) ? 1 : 0);
    }

    /**
     * 删除未/未激活扣款记录
     */
    @PreAuthorize("@ss.hasPermi('pos:records:remove')" )
    @Log(title = "未/未激活扣款记录" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{deductionIds}" )
    public AjaxResult remove(@PathVariable Long[] deductionIds) {
        return toAjax(iAizDeductionRecordsService.removeByIds(Arrays.asList(deductionIds)) ? 1 : 0);
    }



//    //app  扣款记录表 只查询直属的
//    @PostMapping("/app/back/deduction/records")
//    public AjaxResult appBackDeductionRecords(@RequestBody AizDeductionRecords aizDeductionRecords){
//        return iAizDeductionRecordsService.appBackDeductionRecords(aizDeductionRecords);
//    }
}
